package com.jt.sso.server.controller;


import com.jt.sso.server.service.IUserService;
import com.jt.sso.server.vo.RegisterVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;



@RestController
@Slf4j
public class SystemController {

    //Ctrl+Alt+B可以直接跳转到这个接口的实现类
    @Autowired
    private IUserService userService;

    @PostMapping("/register")
    //@Validated表示激活紧随其后的类型的SpringValidation验证
    //要验证的对象参数后面新增一个参数类型为BindingResult
    //SpringValidation会将验证结果自动赋值到这个对象中
    public String registerStudent(
            @Validated RegisterVo registerVo,
            BindingResult result) {
        //第二个参数registerVo会自动赋值到第一个参数中的{}的位置
        log.debug("获得用户填写的信息:{}", registerVo);
        //判断result对象中有没有错误
        if (result.hasErrors()) {

            String msg = result.getFieldError()
                    .getDefaultMessage();
            return msg;
        }
        //执行注册
        userService.registerUser(registerVo);
        return "注册成功";
    }



}
